﻿using System;
using System.IO;

namespace Numble
{
    class Menu
    {
        public static void PrintMenu(int choose, int n)
        {
            switch (choose)
            {
                case 0:
                    PlayFrame(n);
                    Help(n);
                    Scores(n);
                    Exit(n);
                    break;
                case 1:
                    Play(n);
                    HelpFrame(n);
                    Scores(n);
                    Exit(n);
                    break;
                case 2:
                    Play(n);
                    Help(n);
                    ScoresFrame(n);
                    Exit(n);
                    break;
                case 3:
                    Play(n);
                    Help(n);
                    Scores(n);
                    ExitFrame(n);
                    break;
            }
        }

        public static void ReadScores()
        {
            int col = 7;
            if (File.Exists(@"score.sc"))
            {
                StreamReader reader = new StreamReader(@"score.sc");
                using (reader)
                {
                    string line = reader.ReadLine();
                    int count = 1;
                    while (line != null && count < 6)
                    {
                        var currLine = line.Split('-');
                        Console.SetCursorPosition(12, ++col);
                        Console.WriteLine(count++ + ". " + currLine[0] + " " + currLine[1]);
                        line = reader.ReadLine();
                        col++;
                    }
                }
            }
            else
            {
                Console.WriteLine("NO HIGH SCORES ?");
            }
            Console.SetCursorPosition(17, 28);
            Console.Write("Press any key...");
            Console.ReadLine();
        }

        public static void ReadHelp()
        {
            Console.SetCursorPosition(0, 0);
            if (File.Exists(@"helpers.help"))
            {
                Console.Clear();
                StreamReader reader = new StreamReader(@"helpers.help");
                using (reader)
                {
                    string text = reader.ReadToEnd();
                    Console.WriteLine(text);
                }
                Console.SetCursorPosition(17, 28);
                Console.WriteLine("Press any key...".ToUpper());
                Console.ReadLine();
            }
            else
            {
                Console.SetCursorPosition(0, 27);
                Console.WriteLine("File is not exist, ask from developer team");
                Console.WriteLine("Press any key to continue".ToUpper());
                Console.ReadLine();
            }
        }

        public static void Play(int size)
        {
            string[,] go = 
                {
                {"0020","0020","0020","0020","0020","0020","0020","0020","0020","0020"},
                {"0020","0020","0020","0050","004C","0041","0059","0020","0020","0020"},
                {"0020","0020","0020","0020","0020","0020","0020","0020","0020","0020"},
                };

            int heigth = size + 4;
            int column = size + 1;

            for (int i = 0; i < go.GetLength(0); i++)
            {
                Console.SetCursorPosition(heigth, column++);

                for (int j = 0; j < go.GetLength(1); j++)
                {
                    char a = (char)int.Parse(go[i, j], System.Globalization.NumberStyles.HexNumber);
                    Console.Write(a);
                }
                Console.WriteLine();
            }
        }

        public static void Help(int n)
        {
            string[,] help = 
                {
                {"0020","0020","0020","0020","0020","0020","0020","0020","0020","0020"},
                {"0020","0020","0020","0048","0045","004C","0050","0020","0020","0020"},
                {"0020","0020","0020","0020","0020","0020","0020","0020","0020","0020"},
                };
            int heigth = n + 4;
            int column = n + 4;

            for (int i = 0; i < help.GetLength(0); i++)
            {
                Console.SetCursorPosition(heigth, column++);
                for (int j = 0; j < help.GetLength(1); j++)
                {
                    char a = (char)int.Parse(help[i, j], System.Globalization.NumberStyles.HexNumber);
                    Console.Write(a);
                }
                Console.WriteLine();
            }
        }

        public static void Scores(int n)
        {
            string[,] scores = 
                {
                {"0020","0020","0020","0020","0020","0020","0020","0020","0020","0020"},
                {"0020","0020","0053","0043","004F","0052","0045","0053","0020","0020"},
                {"0020","0020","0020","0020","0020","0020","0020","0020","0020","0020"},
                };
            int heigth = n + 4;
            int column = n + 7;

            for (int i = 0; i < scores.GetLength(0); i++)
            {
                Console.SetCursorPosition(heigth, column++);

                for (int j = 0; j < scores.GetLength(1); j++)
                {
                    char a = (char)int.Parse(scores[i, j], System.Globalization.NumberStyles.HexNumber);
                    Console.Write(a);
                }
                Console.WriteLine();
            }
        }

        public static void Exit(int n)
        {
            string[,] exit = 
                {
                {"0020","0020","0020","0020","0020","0020","0020","0020","0020","0020"},
                {"0020","0020","0020","0045","0058","0049","0054","0020","0020","0020"},
                {"0020","0020","0020","0020","0020","0020","0020","0020","0020","0020"},
                };
            int heigth = n + 4;
            int column = n + 10;


            for (int i = 0; i < exit.GetLength(0); i++)
            {
                Console.SetCursorPosition(heigth, column++);

                for (int j = 0; j < exit.GetLength(1); j++)
                {
                    char a = (char)int.Parse(exit[i, j], System.Globalization.NumberStyles.HexNumber);
                    Console.Write(a);
                }
                Console.WriteLine();
            }
        }

        public static void PlayFrame(int n)
        {
            string[,] go = 
                {
                {"250C","2500","2500","2500","2500","2500","2500","2500","2500","2510"},
                {"0020","0020","0020","0050","004C","0041","0059","0020","0020","0020"},
                {"2514","2500","2500","2500","2500","2500","2500","2500","2500","2518"},
                };
            int heigth = n + 4;
            int column = n + 1;

            for (int i = 0; i < go.GetLength(0); i++)
            {
                Console.SetCursorPosition(heigth, column++);

                for (int j = 0; j < go.GetLength(1); j++)
                {
                    char a = (char)int.Parse(go[i, j], System.Globalization.NumberStyles.HexNumber);
                    Console.Write(a);
                }
                Console.WriteLine();
            }
        }

        public static void HelpFrame(int n)
        {
            string[,] help = 
                {
                {"250C","2500","2500","2500","2500","2500","2500","2500","2500","2510"},
                {"0020","0020","0020","0048","0045","004C","0050","0020","0020","0020"},
                {"2514","2500","2500","2500","2500","2500","2500","2500","2500","2518"},
                };
            int heigth = n + 4;
            int column = n + 4;

            for (int i = 0; i < help.GetLength(0); i++)
            {
                Console.SetCursorPosition(heigth, column++);

                for (int j = 0; j < help.GetLength(1); j++)
                {
                    char a = (char)int.Parse(help[i, j], System.Globalization.NumberStyles.HexNumber);
                    Console.Write(a);
                }
                Console.WriteLine();
            }
        }

        public static void ScoresFrame(int n)
        {
            string[,] scores = 
                {
                {"250C","2500","2500","2500","2500","2500","2500","2500","2500","2510"},
                {"0020","0020","0053","0043","004F","0052","0045","0053","0020","0020"},
                {"2514","2500","2500","2500","2500","2500","2500","2500","2500","2518"},
                };
            int heigth = n + 4;
            int column = n + 7;

            for (int i = 0; i < scores.GetLength(0); i++)
            {
                Console.SetCursorPosition(heigth, column++);

                for (int j = 0; j < scores.GetLength(1); j++)
                {
                    char a = (char)int.Parse(scores[i, j], System.Globalization.NumberStyles.HexNumber);
                    Console.Write(a);
                }
                Console.WriteLine();
            }
        }

        public static void ExitFrame(int n)
        {
            string[,] exit = 
                {
                {"250C","2500","2500","2500","2500","2500","2500","2500","2500","2510"},
                {"0020","0020","0020","0045","0058","0049","0054","0020","0020","0020"},
                {"2514","2500","2500","2500","2500","2500","2500","2500","2500","2518"},
                };

            int heigth = n + 4;
            int column = n + 10;

            for (int i = 0; i < exit.GetLength(0); i++)
            {
                Console.SetCursorPosition(heigth, column++);

                for (int j = 0; j < exit.GetLength(1); j++)
                {
                    char a = (char)int.Parse(exit[i, j], System.Globalization.NumberStyles.HexNumber);
                    Console.Write(a);
                }
                Console.WriteLine();
            }
        }
    }
}

